﻿// Inner Fire 游戏引擎库
// UI - 按钮
//
// Copyright (c) 2024 by 尔西大帝. All rights reserved.
//
// 用于UI的组件-Button
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2024-12-25

#pragma once

#include <ui/component/ui_component.h>
#include <ui/component/label.h>
#include <ui/component/ui_image.h>
#include <ui/prefab/button_info.h>
#include <functional>

namespace ifire::ui {


struct ButtonText {};

class Button : public UIComponent {
public:
  Button() = default;
  Button(ikit::sstr name_id, const ButtonInfo* info);
  Button(const Button& lhs) = delete;
  Button& operator=(const Button& lhs) = delete;
  ~Button() = default;

  const ButtonInfo* Info() const { return info_; }
  Label* Text() const { return button_text_.get(); }
  Image* ButtonImage() const { return button_image_.get(); }
  Image* IconImage() const { return icon_image_.get(); }
  dx::DxLayout* Layout() const { return layout_; }

  void SetText(const char* text);
  void SetIcon(const char* icon);

  inline void SetLayout(dx::DxLayout* layout) { layout_ = layout; }
  void SetScale(XMFLOAT2 scale) override;
  void SetRefresh() override;

private:
  const ButtonInfo* info_;
  std::unique_ptr<Image> button_image_ = nullptr;
  std::unique_ptr<Image> icon_image_ = nullptr;
  std::unique_ptr<Label> button_text_ = nullptr;
  dx::DxLayout* layout_ = nullptr;
  ButtonState state_ = ButtonState::NORMAL;
};

using ButtonPtr = std::unique_ptr<Button>;

} // namespace ifire::ui